package test.test;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : example
 * @ Author: XuLeHuang
 * @ Date: 2022/12/20 16:17
 * @ Description:
 */
public class AppTest1 {
    public static void main(String[] args) {
        List<Integer> arrayList = new ArrayList<Integer>();
        // 每个集合插入5万条数据
        for (int i = 0; i < 50000; i++) {
            arrayList.add(i);
        }

        int arry = 0;

        System.out.println("============遍历arrayList============");

        // 用for循环arrayList
        long forStartTime = System.currentTimeMillis();
        for (int i = 0; i < arrayList.size(); i++) {
            arry = arrayList.get(i);
        }
        long forEndTime = System.currentTimeMillis();
        System.out.println("for遍历需要：" + (forEndTime - forStartTime) + "毫秒");


        // 用增强for循环arrayList
        long forUpStartTime = System.currentTimeMillis();
        for (Integer in : arrayList) {
            arry = in;
        }
        long forUpEndTime = System.currentTimeMillis();
        System.out.println("增强for遍历需要：" + (forUpEndTime - forUpStartTime) + "毫秒");

        /** []数组普通和增强for一样，编译后一样，一样要goto*/

        /*** ArrList集合类型的都是增强for*/

        /** LinkedList根据书写方式变化*/

    }
}
